<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <a href="./内置属性 + 自定义属性.html" data-my-data="my-data">Hello world!</a>

  <script>
    const elem = document.querySelector('a')

    // 获取
    const href = elem.getAttribute('href')
    const myData = elem.getAttribute('data-my-data')
    console.log(href)
    console.log(myData)

    // 修改
    elem.setAttribute('href', 'https://www.baidu.com')
    elem.setAttribute('data-my-data', 'my-data 2')

    // 删除
    elem.removeAttribute('href')
    elem.removeAttribute('data-my-data')
  </script>
</body>

</html>